
import { Button, Result } from 'antd'
import { useRequest } from 'alova/client'

import { Http } from '../../API'
import { PutIndexedDB } from '../../Utils/IndexedDB'

const WeChartUnbind = ({ Off, ModalEvent }) => {


    const { send } = useRequest(() => Http({ url: 'posWeChatUnding' }), { immediate: false })
    const { send: getOperator } = useRequest(() => Http({ url: 'getOperator' }), { immediate: false })

    const unBind = () => {
        send().then(() => {
            getOperator().then(async res => {
                await PutIndexedDB('userInfo', res.list)
                ModalEvent.emit({ type: 'RefreshUser' })
                Off()
            })
        })
    }

    return (
        <Result
            status="warning"
            title="正在解除微信绑定关系,是否确认解除绑定?"
            extra={<Button type="primary" key="console" danger onClick={unBind}>解除绑定</Button>}
        />
    );
};

export default WeChartUnbind;